package com.example.demo.service.Impl;

import com.example.demo.entity.Course;
import com.example.demo.map.CourseMapper;
import com.example.demo.service.CourseService;
import com.example.demo.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class CourseServiceImpl implements CourseService {
    @Override
    public List<Course> queryAllCourse() {
        SqlSession sqlSession = MybatisUtil.getSqlSession();
        //查询课程数据，返回给页面
        CourseMapper mapper = sqlSession.getMapper(CourseMapper.class);
        List<Course> courses = mapper.queryCourse();
        sqlSession.close();
        return courses;
    }

    @Override
    public Course queryCourseById(int id) {
        SqlSession sqlSession = MybatisUtil.getSqlSession();
        //查询课程数据，返回给页面
        CourseMapper mapper = sqlSession.getMapper(CourseMapper.class);
        Course courses = mapper.queryCourseById(id);
        sqlSession.close();
        return courses;
    }
}
